fix(loops): fix loops on empty collection#3049
Merged
icecrasher321 merged 4 commits intostagingfrom Jan 28, 2026
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
Greptile OverviewGreptile SummaryFixed a critical bug where loops with empty collections (forEach with empty arrays or for loops with 0 iterations) would incorrectly execute the loop body once instead of being skipped entirely. Key Changes:
The fix ensures proper control flow by preventing the loop body from executing when the initial condition evaluation returns false (empty collection case). Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Engine as Execution Engine
participant NodeOrch as Node Orchestrator
participant LoopOrch as Loop Orchestrator
participant EdgeMgr as Edge Manager
participant DAG as DAG
Note over Engine,DAG: Loop with Empty Collection Flow
Engine->>NodeOrch: Execute loop sentinel start
NodeOrch->>LoopOrch: evaluateInitialCondition(loopId)
alt forEach with empty items
LoopOrch-->>NodeOrch: return false (skip loop)
else for with 0 iterations
LoopOrch-->>NodeOrch: return false (skip loop)
else while/doWhile
LoopOrch-->>NodeOrch: evaluate condition
end
NodeOrch-->>Engine: {sentinelStart: true, shouldExit: true, selectedRoute: LOOP_EXIT}
Engine->>EdgeMgr: getNextNodes(output)
EdgeMgr->>EdgeMgr: Activate LOOP_EXIT edge
Note over EdgeMgr: NEW: Skip node reactivation check<br/>when selectedRoute is LOOP_EXIT
EdgeMgr->>DAG: Find target via LOOP_EXIT edge
Note over DAG: Edge created only if target<br/>is outside loop (originalTarget check)
EdgeMgr-->>Engine: [nextNode outside loop]
Engine->>Engine: Continue execution after loop
|
Collaborator
|
@cursor review |
1 similar comment
Collaborator
|
@cursor review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Type of Change
Testing
Tested with @icecrasher321
Checklist